<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./lib/vue.js"></script>
    <link rel="stylesheet" href="./css/animate.css">

    <style>
        /* 2.自定义两组样式，来控制transition内部元素实现动画 */
        /* v-enter【这是一个时间点】是进入之前，元素的起始状态，此时还没有开始进入 */
        /* v-leave-to【这是一个时间点】是动画离开之后，离开的终止状态，此时元素动画已经结束了 */
        .v-enter,
        .v-leave-to {
            opacity: 0;
            transform: translateX(80px);
        }

        /* v-enter-active【入场动画时间段】 */
        /* v-leave-active【出场动画时间段】 */
        .v-enter-active,
        .v-leave-active {
            transition: all 1s ease;
        }


        /* 自定义前缀 */
        .my-enter,
        .my-leave-to {
            opacity: 0;
            transform: translateY(80px);
        }

        .my-enter-active,
        .my-leave-active {
            transition: all 1s ease;
        }
    </style>
</head>

<body>
    <div id="app">
        <!-- 无动画效果 -->
        <h2>无动画效果</h2>
        <button @click="flag = !flag">toggle</button>
        <h3 v-if="flag">我是H3</h3>

        <hr>

        <!-- 有动画效果 -->
        <!-- 1.使用transition元素，把需要被动画控制的元素包裹起来 -->
        <!-- transition元素，是Vue官方提供的 -->
        <h2>有动画效果</h2>
        <button @click="flag2 = !flag2">toggle</button>
        <transition>
            <h3 v-if="flag2">我是H3</h3>
        </transition>

        <hr>

        <!-- 自定义前缀 -->
        <h2>自定义前缀</h2>
        <button @click="flag3 = !flag3">toggle</button>
        <transition name="my">
            <h3 v-if="flag3">我是H3</h3>
        </transition>


        <hr>

        <!-- 使用第三方类库 -->
        <!-- 入场bounceIn 离场bounceOut -->
        <h2>使用第三方类库</h2>
        <button @click="flag4 = !flag4">toggle</button>
        <transition enter-active-class="animated bounceIn" leave-active-class="animated bounceOut">
            <h3 v-if="flag4">我是H3</h3>
        </transition>
        <!-- 将animated放到元素身上就只用写一次 -->
        <transition enter-active-class="bounceIn" leave-active-class="bounceOut" :duration="{ enter: 1000, leave: 1000}">
            <h3 v-if="flag4" class="animated">我是H3</h3>
        </transition>
        <!-- :duration指定入场和离场动画时间 -->
        <transition enter-active-class="bounceIn" leave-active-class="bounceOut" :duration="200">
            <h3 v-if="flag4" class="animated">我是H3</h3>
        </transition>
        <!-- 分别指定入场和离场动画时间 -->
        <transition enter-active-class="bounceIn" leave-active-class="bounceOut" :duration="{ enter: 400, leave: 200}">
            <h3 v-if="flag4" class="animated">我是H3</h3>
        </transition>
        <hr>

    </div>
</body>
<script>
    var vm = new Vue({
        el: "#app",
        data: {
            flag: false,
            flag2: false,
            flag3: false,
            flag4: false
        },
        methods: {

        }
    });
</script>

</html>